return;
const source = MessageTray.getSystemSource();
- const notification = new MessageTray.Notification(
+ const notification = new MessageTray.Notification({
source,
- mount.get_name()
- );
+ title: mount.get_name(),
+ });
notification.connect('activate', () => {
const app = Gio.app_info_get_default_for_type('inode/directory', false);
startAppForMount(app, mount);
}
const source = MessageTray.getSystemSource();
- const notification = new MessageTray.Notification(source, title, body);
+ const notification = new MessageTray.Notification({source, title, body});
notification.iconName = 'dialog-password-symbolic';
notification.connect('activated', () => {
let source = new ExtensionUpdateSource();
Main.messageTray.add(source);
- let notification = new MessageTray.Notification(source,
- _('Extension Updates Available'),
- _('Extension updates are ready to be installed.'));
+ const notification = new MessageTray.Notification({
+ source,
+ title: _('Extension Updates Available'),
+ body: _('Extension updates are ready to be installed.'),
+ });
notification.connect('activated',
() => source.open());
source.addNotification(notification);
return; // assume user action
const source = MessageTray.getSystemSource();
- const notification = new MessageTray.Notification(source,
- _('System was put in unsafe mode'),
- _('Apps now have unrestricted access'));
+ const notification = new MessageTray.Notification({
+ source,
+ title: _('System was put in unsafe mode'),
+ body: _('Apps now have unrestricted access'),
+ });
notification.addAction(_('Undo'),
() => (global.context.unsafe_mode = false));
notification.setTransient(true);
*/
export function notify(msg, details) {
const source = MessageTray.getSystemSource();
- let notification = new MessageTray.Notification(source, msg, details);
+ const notification = new MessageTray.Notification({
+ source,
+ title: msg,
+ body: details,
+ });
notification.setTransient(true);
source.addNotification(notification);
}
});
export class Notification extends GObject.Object {
- _init(source, title, banner, params) {
- super._init({source});
+ constructor(params) {
+ super(params);
- this.title = title;
- this.urgency = Urgency.NORMAL;
- // 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
- this.isTransient = false;
- this.privacyScope = PrivacyScope.USER;
- this.forFeedback = false;
- this.body = null;
- this.useBodyMarkup = false;
- this.sound = null;
- this._soundPlayed = false;
- this.actions = [];
- this.setResident(false);
-
- // If called with only one argument we assume the caller
- // will call .update() later on. This is the case of
- // NotificationDaemon, which wants to use the same code
- // for new and updated notifications
- if (arguments.length !== 1)
- this.update(title, banner, params);
+ this._actions = [];
+
+ if (!this.datetime)
+ this.datetime = GLib.DateTime.new_now_local();
}
// update:
this.emit('updated', params.clear);
}
+ get actions() {
+ return this._actions;
+ }
+
get iconName() {
if (this.gicon instanceof Gio.ThemedIcon)
return this.gicon.iconName;
this.destroy();
});
- this.actions.push(action);
+ this._actions.push(action);
this.emit('action-added', action);
}
clearActions() {
- if (this.actions.length === 0)
+ if (this._actions.length === 0)
return;
- this.actions.forEach(action => {
+ this._actions.forEach(action => {
this.emit('action-removed', action);
});
- this.actions = [];
+ this._actions = [];
}
setUrgency(urgency) {
? this._getSourceForApp(sender, app)
: this._getSourceForPidAndName(sender, pid, appName);
- notification = new MessageTray.Notification(source);
+ notification = new MessageTray.Notification({source});
this._notifications.set(id, notification);
notification.connect('destroy', (n, reason) => {
this._notifications.delete(id);
const GtkNotificationDaemonNotification = GObject.registerClass(
class GtkNotificationDaemonNotification extends MessageTray.Notification {
- _init(source, id, notification) {
- super._init(source);
+ constructor(source, id, notification) {
+ super({source});
this._serialized = GLib.Variant.new('a{sv}', notification);
this.id = id;
let forFeedback = options.forFeedback;
if (!this._notification) {
- this._notification = new MessageTray.Notification(source, text, null);
+ this._notification = new MessageTray.Notification({
+ source,
+ title: text,
+ });
this._notification.setTransient(true);
this._notification.setForFeedback(forFeedback);
this._notification.connect('destroy', () => delete this._notification);
title: _('Screenshot'),
iconName: 'screencast-recorded-symbolic',
});
- const notification = new MessageTray.Notification(
+ const notification = new MessageTray.Notification({
source,
title,
// Translators: notification body when a screencast was recorded.
- this._screencastPath ? _('Click here to view the video.') : ''
- );
+ body: this._screencastPath ? _('Click here to view the video.') : '',
+ });
notification.setTransient(true);
if (this._screencastPath) {
title: _('Screenshot'),
iconName: 'screenshot-recorded-symbolic',
});
- const notification = new MessageTray.Notification(
+ const notification = new MessageTray.Notification({
source,
// Translators: notification title.
- _('Screenshot captured'),
+ title: _('Screenshot captured'),
// Translators: notification body when a screenshot was captured.
- _('You can paste the image from the clipboard.'),
- {datetime: time, gicon: content}
- );
+ body: _('You can paste the image from the clipboard.'),
+ datetime: time,
+ gicon: content,
+ });
if (!disableSaveToDisk) {
// Translators: button on the screenshot notification.
this._notification?.destroy();
const source = MessageTray.getSystemSource();
- this._notification = new MessageTray.Notification(source, title, body);
+ this._notification = new MessageTray.Notification({source, title, body});
this._notification.setTransient(true);
this._notification.iconName = 'media-removable-symbolic';
this._notification?.destroy();
const source = MessageTray.getSystemSource();
- this._notification = new MessageTray.Notification(source,
- _('Connection failed'),
- _('Activation of network connection failed'));
+ this._notification = new MessageTray.Notification({
+ source,
+ title: _('Connection failed'),
+ body: _('Activation of network connection failed'),
+ });
this._notification.iconName = 'network-error-symbolic';
this._notification.setUrgency(MessageTray.Urgency.HIGH);
this._notification.setTransient(true);
this._notification.destroy();
const source = MessageTray.getSystemSource();
- this._notification = new MessageTray.Notification(source, title, body);
+ this._notification = new MessageTray.Notification({source, title, body});
this._notification.iconName = 'thunderbolt-symbolic';
this._notification.setUrgency(MessageTray.Urgency.HIGH);
this._notification.connect('destroy', () => {
let source = new WindowAttentionSource(app, window);
Main.messageTray.add(source);
- let [title, banner] = this._getTitleAndBanner(app, window);
+ let [title, body] = this._getTitleAndBanner(app, window);
- let notification = new MessageTray.Notification(source, title, banner);
+ let notification = new MessageTray.Notification({source, title, body});
notification.connect('activated', () => {
source.open();
});
source.addNotification(notification);
window.connectObject('notify::title', () => {
- [title, banner] = this._getTitleAndBanner(app, window);
- notification.update(title, banner);
+ [title, body] = this._getTitleAndBanner(app, window);
+ notification.update(title, body);
}, source);
}
}
source.connect('notification-request-banner',
() => Scripting.scriptEvent('notificationShowDone'));
- const notification = new MessageTray.Notification(source,
- 'A test notification');
+ const notification = new MessageTray.Notification({
+ source,
+ title: 'A test notification',
+ });
source.addNotification(notification);
await Scripting.sleep(400);